/*
var locat = (window.location+'').split('/');
$(function(){if('tool'== locat[3]){locat =  locat[0]+'//'+locat[2];}else{locat =  locat[0]+'//'+locat[2]+'/'+locat[3];};});

$(top.hangge());

$(top.hangge());

function openMap(){
   var result = showModalDialog(locat+"/tool/mapXY.do","","dialogWidth=650px;dialogHeight=500px;");
   if(result==null || ""==result){
	      		return;
   }else{
    var result=result.split("-");
		document.getElementById("ZUOBIAO_X").value=result[0];
		document.getElementById("ZUOBIAO_Y").value=result[1];
	   }
}
function openMap2(){
	   var result = showModalDialog(locat+"/tool/mapXY.do","","dialogWidth=650px;dialogHeight=500px;");
	   if(result==null || ""==result){
	      		return;
	   }else{
	    var result=result.split("-");
		document.getElementById("ZUOBIAO_X2").value=result[0];
  		document.getElementById("ZUOBIAO_Y2").value=result[1];
  	   }
	}
//去后计算
function getDistance(){
	if($("#ZUOBIAO_Y").val()==""){
		$("#ZUOBIAO_Y").tips({
			side:3,
            msg:'不能为空',
            bg:'#AE81FF',
            time:2
        });
		$("#ZUOBIAO_Y").focus();
		return false;
	}
	if($("#ZUOBIAO_X").val()==""){
		$("#ZUOBIAO_X").tips({
			side:3,
            msg:'不能为空',
            bg:'#AE81FF',
            time:2
        });
		$("#ZUOBIAO_X").focus();
		return false;
	}
	if($("#ZUOBIAO_Y2").val()==""){
		$("#ZUOBIAO_Y2").tips({
			side:3,
            msg:'不能为空',
            bg:'#AE81FF',
            time:2
        });
		$("#ZUOBIAO_Y2").focus();
		return false;
	}
	if($("#ZUOBIAO_X2").val()==""){
		$("#ZUOBIAO_X2").tips({
			side:3,
            msg:'不能为空',
            bg:'#AE81FF',
            time:2
        });
		$("#ZUOBIAO_X2").focus();
		return false;
	}
	$.ajax({
		type: "POST",
		url: locat+'/tool/getDistance.do',
    	data: {ZUOBIAO_X:$("#ZUOBIAO_X").val(),ZUOBIAO_Y:$("#ZUOBIAO_Y").val(),ZUOBIAO_X2:$("#ZUOBIAO_X2").val(),ZUOBIAO_Y2:$("#ZUOBIAO_Y2").val(),tm:new Date().getTime()},
		dataType:'json',
		cache: false,
		success: function(data){
			 if("success" == data.result){
				 if('null' == data.distance || null == data.distance){
					 $("#distance").text("计算失败,参数有误");
				 }else{
					 $("#distance").tips({
							side:1,
				            msg:'计算结果',
				            bg:'#75C117',
				            time:3
				     });
					 $("#distance").val(data.distance);
				 }
			 }else{
				 $("#distance").tips({
						side:3,
			            msg:'计算失败,参数有误',
			            bg:'#FF5080',
			            time:10
			     });
				 return;
			 }
		}
	});
}*/


function validate() {
	var sever_add = document.getElementsByName('sever_add')[0].value;
	if (isNull(sever_add)) {
		alert('请选择地址');
		return false;
	}
	return true;
}

<!-- 将百度地图API引入，设置好自己的key -->
document.write('<script language=javascript src="http://api.map.baidu.com/api?v=2.0&ak=ANZzKlRb2LUYHnCGknTdH50DMGflQzmj"></script>');
//判断是否是空
function isNull(a) {
	return (a == '' || typeof(a) == 'undefined' || a == null) ? true : false;
}

/*document.getElementById('open').onclick = function () {
	if (document.getElementById('allmap').style.display == 'none') {
		document.getElementById('allmap').style.display = 'block';
	} else {
		document.getElementById('allmap').style.display = 'none';
	}
}*/

var map = new BMap.Map("allmap");
var geoc = new BMap.Geocoder();   //地址解析对象
var markersArray = [];
var geolocation = new BMap.Geolocation();


var point = new BMap.Point(116.331398, 39.897445);
map.centerAndZoom(point, 12); // 中心点
geolocation.getCurrentPosition(function (r) {
	if (this.getStatus() == BMAP_STATUS_SUCCESS) {
		var mk = new BMap.Marker(r.point);
		map.addOverlay(mk);
		map.panTo(r.point);
		map.enableScrollWheelZoom(true);
	}
	else {
		alert('failed' + this.getStatus());
	}
}, {enableHighAccuracy: true})
map.addEventListener("click", showInfo);

var localSearch = new BMap.LocalSearch(map);
localSearch.enableAutoViewport();
//清除标识
function clearOverlays() {
	if (markersArray) {
		for (i in markersArray) {
			map.removeOverlay(markersArray[i])
		}
	}
}
//地图上标注
function addMarker(point) {
	var marker = new BMap.Marker(point);
	markersArray.push(marker);
	clearOverlays();
	map.addOverlay(marker);
}
//点击地图时间处理
function showInfo(e) {
	document.getElementById('BUILDING_LNG').value = e.point.lng;
	document.getElementById('BUILDING_LAT').value =  e.point.lat;
	geoc.getLocation(e.point, function (rs) {
		var addComp = rs.addressComponents;
		var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
		if (confirm("确定要地址是" + address + "?")) {
			document.getElementById('allmap').style.display = 'none';
			document.getElementById('sever_add').value = address;
		}
	});
	addMarker(e.point);
}

document.getElementById('mapopen').onclick = function () {
	/* map = new BMap.Map("allmap");
	 var geoc = new BMap.Geocoder();   //地址解析对象
	 var markersArray = [];
	 var geolocation = new BMap.Geolocation();
	 var point = new BMap.Point(121.491, 31.233);
	 map.centerAndZoom("北京", 12); // 中心点*/
	console.log('test');

	var keyword = document.getElementById("BUILDING_NAME").value;
	localSearch.setSearchCompleteCallback(function (searchResult) {
		var poi = searchResult.getPoi(0);
		console.log(poi.point.lng);
		document.getElementById("BUILDING_LNG").value = poi.point.lng ; //获取经度和纬度，将结果显示在文本框中
		document.getElementById("BUILDING_LAT").value =  poi.point.lat;
		//map.centerAndZoom(poi.point, 13);
	});
	localSearch.search(keyword);

}


